package com.design_pattern._03_behavioral._06_observer;

import java.util.Observable;
import java.util.Observer;

public class Baby { // 没用到
    boolean cry; // default false

}

class MumObserer implements Observer{
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof BabyObservable){
            System.out.println("((BabyObservable) o).source = " + ((BabyObservable) o).source);
        }
        System.out.println(this.getClass().getSimpleName()+"arg = " + arg);
    }
}

class DadObserer implements Observer{
    @Override
    public void update(Observable o, Object arg) {
        if (o instanceof BabyObservable){
            System.out.println("((BabyObservable) o).source = " + ((BabyObservable) o).source);
        }
        System.out.println(this.getClass().getSimpleName()+"arg = " + arg);
    }
}

class BabyObservable extends Observable {
    Baby source;
    public void cry(Baby baby, String arg){
        source = baby;
        setChanged(); // 标识发生变化
        notifyObservers(arg);// 发送通知
    }

}